﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace EmployeeCheckIn
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                SerchDB loaddate = new SerchDB();
                DataTable loadtb = loaddate.timeofdate();
                HidTime.Value = Convert.ToDateTime( loadtb.Rows[0]["DAY_OF_EDIT"].ToString()).ToString("dd/MM/yyyy");
                txt_TimeOfDay.Text = loadtb.Rows[0]["TIME_OF_START"].ToString();
                txt_TimeOfLate.Text = loadtb.Rows[0]["TIME_OF_LATE"].ToString();
                txt_money.Text = loadtb.Rows[0]["LATE_MONEY"].ToString();
            }
        }

        private void LoadDefault()
        {
            SerchDB loaddate = new SerchDB();
            DataTable loadtb = loaddate.timeofdate();
            HidTime.Value = Convert.ToDateTime(loadtb.Rows[0]["DAY_OF_EDIT"].ToString()).ToString("dd/MM/yyyy");
            txt_TimeOfLate.Text = loadtb.Rows[0]["TIME_OF_LATE"].ToString();
            txt_TimeOfDay.Text = loadtb.Rows[0]["TIME_OF_START"].ToString();
            txt_money.Text = loadtb.Rows[0]["LATE_MONEY"].ToString();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            if (Session["User"] != null && Session["Pass"] != null)
            {
                LoadDefault();
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
            
        }

        

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Session["User"] != null && Session["Pass"] != null)
            {
                string DateStart = Convert.ToDateTime(HidTime.Value).ToString("yyyy/MM/dd", new System.Globalization.CultureInfo("en-US")) + " " + txt_TimeOfDay.Text;
                InSertData EditTime = new InSertData();
                EditTime.updateTimeOfDate(DateStart, txt_TimeOfDay.Text,txt_TimeOfLate.Text,Convert.ToInt32(txt_money.Text));
                StringBuilder sb = new StringBuilder();
                sb.Append("<script language='javascript' type = 'text/javascript'>");
                sb.Append("alert('แก้ไขข้อมูลเรียบร้อย')");
                sb.Append("</script>");
                Response.Write(sb.ToString());
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }

        
    }
}